(function() {
  var _cards = [
    'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9',
    'C7S', 'C8S', 'C9S', 'CTS', 'CJS', 'CQS', 'CKS', 'CAS',
    'C7C', 'C8C', 'C9C', 'CTC', 'CJC', 'CQC', 'CKC', 'CAC',
    'C7D', 'C8D', 'C9D', 'CTD', 'CJD', 'CQD', 'CKD', 'CAD',
    'C7H', 'C8H', 'C9H', 'CTH', 'CJH', 'CQH', 'CKH', 'CAH'];

  deberc.gameRoomViewPlayer = function(containerId) {
    var _container = document.getElementById(containerId);
    var _containerId = containerId;
    var cards = '';
    for (var i in _cards) {
      cards += '<div class="c ' + _cards[i] + '"><div class="t"></div><div class="m"></div><div class="b"></div></div>';
    }
    document.getElementById(_containerId + '_h').innerHTML = cards;

    this.init = function(playerId, isDealer, scores, cards) {
      if (deberc.rest.session.isCurrent(playerId)) {
        _container.className = 'p b';
        document.getElementById(_containerId + '_n').innerHTML = 'Вы';
        document.getElementById(_containerId + '_n').className = 'd';
      }
      else {
        _container.className = 'p t';
        document.getElementById(_containerId + '_n').innerHTML = 'Соперник';
        document.getElementById(_containerId + '_n').className = 'd';
      }
      vk.api.getUserInfo(playerId, this, function(info) {
        document.getElementById(_containerId + '_n').innerHTML = info.name;
        document.getElementById(_containerId + '_n').className = 'd link';
        document.getElementById(_containerId + '_i').style.cursor = 'pointer';
        document.getElementById(_containerId + '_i').style.backgroundImage = 'url(' + info.picture + ')';
      })
      document.getElementById(_containerId + '_s').innerHTML = '<span class="gray">Очки:&nbsp;</span>' + scores +
        '(+0)';
      document.getElementById(_containerId + '_c').innerHTML = '<span class="gray">Комбинации:&nbsp;</span>нет';
      document.getElementById(_containerId + '_d').innerHTML = isDealer
        ? 'сдающий'
        : '&nbsp;';
      document.getElementById(_containerId + '_h').className = woody.utils.isArray(cards)
        ? 'h C' + cards.join(' C')
        : 'h C' + cards;
    }
  }
})();
